package cn.wsalix.init;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.wsalix.admin.entity.Permit;
import cn.wsalix.admin.entity.AuthData;
import cn.wsalix.admin.service.PermitService;
import cn.wsalix.admin.service.AuthDataService;

@Service("permitInit")
public class PermitInit {

	@Autowired
	private PermitService permitService;
	@Autowired
	private AuthDataService AuthDataService;
	boolean isExe = false;

	@Transactional
	public void init(boolean create) {
		permitService.delAll();
		List<AuthData> AuthDatas = AuthDataService.findAll();
		for(AuthData obj:AuthDatas){
			Permit permitAdd=new Permit();
			permitAdd.setCode(obj.getCode()+":add");
			permitAdd.setCode(obj.getName()+"新增");
			permitService.add(permitAdd);
			
			Permit permitEdit=new Permit();
			permitEdit.setCode(obj.getCode()+":edit");
			permitEdit.setCode(obj.getName()+"修改");
			permitService.add(permitEdit);
			
			Permit permitList=new Permit();
			permitList.setCode(obj.getCode()+":list");
			permitList.setCode(obj.getName()+"列表");
			permitService.add(permitList);
			
			Permit permitDel=new Permit();
			permitDel.setCode(obj.getCode()+":del");
			permitDel.setCode(obj.getName()+"删除");
			permitService.add(permitDel);
		}
	}

}
